﻿/*
   Open Intel 
   Copyright © 2011 – ISC. All Rights Reserved.
*/
using System;
using System.ServiceModel;
using ISC.RIM.Silverlight;
using ISC.RIM.Silverlight.MDNSFeatureService;
using ISC.RIM.Silverlight.MDNSMapService;

using OI.CatalogService;

#if OI
using OI.DataServiceReference;
using OI.SharingService;
#endif

namespace OI.Async
{
    public class ServiceClients
    {
        public static CatalogServiceClient CreateCatalogServiceClient()
        {
            var csc = new CatalogServiceClient();
            csc.Endpoint.Address = new EndpointAddress(Configuration.GetBaseURI() + Configuration.CatalogServiceEndpoint);
            return csc;
        }


        public static FeatureServiceClient CreateFeatureServiceClient(EventHandler<QueryCompletedEventArgs> handler)
        {
            return new Services().CreateFeatureServiceProxy(
                    Configuration.GetBaseURI() + Configuration.MDNSEndpoint,
                    handler,
                    null);
        }


        public static MapServiceClient CreateLegendIconServiceClient(EventHandler<GetLegendIconCompletedEventArgs> handler)
        {
            return new Services().CreateMapServiceProxy(
                    Configuration.GetBaseURI() + Configuration.MDNSEndpoint,
                    null,
                    null,
                    handler,
                    null,
                    null);
        }


        public static MapServiceClient CreateMapDefinitionServiceClient(EventHandler<GetBaselineMapDescriptionStateCompletedEventArgs> handler)
        {
            return new Services().CreateMapServiceProxy(
                    Configuration.GetBaseURI() + Configuration.MDNSEndpoint,
                    null,
                    handler,
                    null,
                    null,
                    null);
        }


#if OI
        public static DataPackagingServiceClient CreateDataPackagingServiceClient()
        {
            var dpsc = new DataPackagingServiceClient();
            dpsc.Endpoint.Address = new EndpointAddress(Configuration.GetBaseURI() + Configuration.DataServiceEndpoint);
            dpsc.InnerChannel.OperationTimeout = new TimeSpan(0, 10, 0);
            return dpsc;
        }


        public static SharingServiceClient CreateSharingServiceClient()
        {
            var ssc = new SharingServiceClient();
            ssc.Endpoint.Address = new EndpointAddress(Configuration.GetBaseURI() + Configuration.SharingServiceEndpoint);
            return ssc;
        }
#endif
    }
}
